import { configureStore } from "@reduxjs/toolkit"
import counterReducer from './counter/counterSlice'
import { useSelector, useDispatch, type TypedUseSelectorHook } from "react-redux"

const store = configureStore({
  reducer: {
    counter: counterReducer
  },
  devTools: true
})

type RootState = ReturnType<typeof store.getState>
type AppDispatch = typeof store.dispatch

// 在整个应用程序中使用，而不是简单的 `useDispatch` 和 `useSelector`
export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

export default store